home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 35.8 KB | 1,242 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWWindow.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifdef FW_PRECOMPILE_BY_LAYER
- #include "FWOS.hpp"
- #endif
-
- #ifdef FW_PRECOMPILE_BY_SUBSYSTEM
- #include "FWWindow.hpp"
- #endif
-
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMEMORY_H
- #include "FWMemory.h"
- #endif
-
- #ifndef FWRESOUR_H
- #include "FWResour.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef FWFCTINF_H
- #include "FWFctInf.h"
- #endif
-
- #ifndef FWWINPRO_H
- #include "FWWinPro.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWGDEV_H
- #include "FWGDev.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(FWMACOS_H)
- #include "FWMacOS.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWBNDSTR_H
- #include "FWBndStr.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODInfo_xh
- #include <Info.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #if defined(FW_BUILD_MAC) & !defined(__RESOURCES__)
- #include <Resources.h>
- #endif
-
- #ifndef FWODMISS_H
- #include "FWODMiss.h"
- #endif
-
- //========================================================================================
- // Runtime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwwindow
- #endif
-
- FW_DEFINE_CLASS_M0(FW_CWindow)
-
- //========================================================================================
- // defines
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #define FW_kSystem75WindoidWDEF 1984 // System 7.5 windoid
- #define FW_kNonSystem75WindoidWDEF 48 // System 7.5 windoid (for system < 7.5)
- #define FW_kSystem75ToggleTBar 1 // Bit 0 tell us whether to hilite/unhilite the tittle bar
- #define FW_kSystem75HasGrow 2 // Bit 1 is the grow bit
- #define FW_kSystem75HasZoom 4 // Bit 2 is the zoom bit
- #define FW_kSystem75VertTBar 8 // bit 3 is for a vertical tittle bar
- #endif
-
- //========================================================================================
- // Static Members
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- Handle FW_CWindow::gMacFloatWindowProc = NULL;
- #endif
-
- //========================================================================================
- // CLASS FW_CWindow
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::FW_CWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow::FW_CWindow(Environment* ev,
- ODPart* thePart,
- ODTypeToken viewType,
- ODTypeToken presentation,
- const FW_CPoint& interiorSize,
- const FW_CPoint& position,
- WindowStyle style) :
- fGraphicDevice(NULL),
- fSession(thePart->GetStorageUnit(ev)->GetSession(ev)),
- fWindowID(kODNULLID)
- {
- FW_CString32 windowTitle(""); // the title doesn't matter
-
- PrivCreateODWindow(ev,
- thePart, NULL,
- TRUE, viewType,
- presentation, windowTitle,
- interiorSize, position,
- style);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::FW_CWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow::FW_CWindow(Environment* ev,
- ODPart* thePart,
- ODFrame* parentFrame,
- FW_Boolean persistent,
- ODTypeToken viewType,
- ODTypeToken presentation,
- const FW_CString& windowTitle,
- const FW_CPoint& interiorSize,
- const FW_CPoint& position,
- WindowStyle style) :
- fGraphicDevice(NULL),
- fSession(thePart->GetStorageUnit(ev)->GetSession(ev)),
- fWindowID(kODNULLID)
- {
- PrivCreateODWindow(ev,
- thePart, parentFrame,
- persistent, viewType,
- presentation, windowTitle,
- interiorSize, position,
- style);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::FW_CWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow::FW_CWindow(Environment* ev,
- ODPart* thePart,
- ODFrame* odFrame) :
- fGraphicDevice(NULL),
- fSession(thePart->GetStorageUnit(ev)->GetSession(ev)),
- fWindowID(kODNULLID)
- {
- PrivCreateODWindowForFrame(ev, thePart, odFrame);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::FW_CWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow::FW_CWindow(Environment* ev, ODPart* thePart, ODID windowID) :
- fGraphicDevice(NULL),
- fSession(thePart->GetStorageUnit(ev)->GetSession(ev)),
- fWindowID(windowID)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::~FW_CWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow::~FW_CWindow()
- {
- if (fGraphicDevice)
- fGraphicDevice->Release();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::AcquireODWindow
- //----------------------------------------------------------------------------------------
-
- ODWindow* FW_CWindow::AcquireODWindow(Environment* ev) const
- {
- FW_ASSERT(fWindowID != NULL);
-
- #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
- return fSession->GetWindowState(ev)->AcquireWindow(ev, fWindowID);
- #else
- return fSession->GetWindowState(ev)->GetWindow(ev, fWindowID);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::Show
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::Show(Environment* ev)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- aqODWindow->Show(ev);
-
- // Because hidden floating window are sent to the back
- if (IsFloating(ev))
- Select(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::GetWindowTitle
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::GetWindowTitle(Environment* ev, FW_CString& windowTiltle) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
-
- #ifdef FW_BUILD_MAC
- Str255 title;
- ::GetWTitle(aqODWindow->GetPlatformWindow(ev), title);
- windowTiltle.ReplaceAll(windowTiltle);
- #endif
-
- #ifdef FW_BUILD_WIN
- char buffer[256];
- ::GetWindowText(aqODWindow->GetPlatformWindow(ev), buffer, 255);
- windowTiltle.ReplaceAll(buffer);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::SetWindowTitle
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::SetWindowTitle(Environment* ev, const FW_CString& windowTiltle)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
-
- #ifdef FW_BUILD_MAC
- Str255 title;
- windowTiltle.ExportPascal(title);
- ::SetWTitle(aqODWindow->GetPlatformWindow(ev), title);
- #endif
-
- #ifdef FW_BUILD_WIN
- ::SetWindowText(aqODWindow->GetPlatformWindow(ev), windowTiltle);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::HideShowOnActivate
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::HideShowOnActivate(Environment* ev, FW_Boolean state)
- {
- FW_UNUSED(state);
- // Don't do anything
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CWindow::PrivCreateODWindowForFrame
- //---------------------------------------------------------------------------------------
-
- void FW_CWindow::PrivCreateODWindowForFrame(Environment* ev,
- ODPart* odPart,
- ODFrame* odFrame)
- {
- #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR2
-
- FW_ASSERT(fWindowID == kODNULLID);
-
- FW_CWindowProperties props(ev);
-
- FW_Boolean hasWinProp = props.ReadWindowProperties(ev, odFrame);
-
- ODPlatformWindow platformWindow = NULL;
-
- #ifdef FW_BUILD_MAC
- FW_CPoint interiorSize(props.fBoundsRect.right - props.fBoundsRect.left,
- props.fBoundsRect.bottom - props.fBoundsRect.top);
- FW_CPoint position(props.fBoundsRect.left, props.fBoundsRect.top);
-
- platformWindow = PrivMacCreatePlatformWindow(ev,
- props.fMacTitle,
- interiorSize,
- position, // ATTENTION: position is the inside position
- props.fMacProcID,
- props.fMacHasCloseBox);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_DEBUG_MESSAGE("Not Implemented Yet!");
- #endif
-
- ODWindowState* windowState = odPart->GetStorageUnit(ev)->GetSession(ev)->GetWindowState(ev);
-
- ODWindow* odWindow = windowState->RegisterWindowForFrame(ev,
- platformWindow,
- odFrame,
- props.fIsRootWindow, // Keeps draft open
- #ifdef FW_BUILD_MAC
- FALSE, // On the Mac we handle the resizing ourself
- #else
- props.fIsResizable, // Is resizable
- #endif
- props.fIsFloating, // Is floating
- TRUE, // should save
- #ifdef FW_BUILD_MAC
- TRUE, // should dispose
- #endif
- props.fSourceFrame);
-
- fWindowID = odWindow->GetID(ev);
-
- FitToScreen(ev);
-
- odWindow->Open(ev);
- if (!hasWinProp)
- odWindow->AdjustWindowShape(ev);
-
- odWindow->Release(ev);
- #else
- FW_DEBUG_MESSAGE("Should not be called with this version");
- #endif
- }
-
- #ifdef FW_BUILD_MAC
- //---------------------------------------------------------------------------------------
- // FW_CWindow::PrivMacCreatePlatformWindow
- //---------------------------------------------------------------------------------------
- // position is the inside position
-
- ODPlatformWindow FW_CWindow::PrivMacCreatePlatformWindow(Environment* ev,
- Str255 windowTitle,
- const FW_CPoint& interiorSize,
- const FW_CPoint& position,
- unsigned short procID,
- FW_Boolean hasCloseBox)
- {
- FW_CAcquireCFMResourceAccess qr;
- FW_SPlatformRect windowRect(position.x.AsInt(), position.y.AsInt(),
- position.x.AsInt() + interiorSize.x.AsInt(),
- position.y.AsInt() + interiorSize.y.AsInt());
-
- Handle windowProc = ::GetResource('WDEF', procID >> 4); // Force load of the resource
- ODPlatformWindow platformWindow = ::NewCWindow(NULL,
- &windowRect,
- windowTitle,
- FALSE,
- procID,
- (WindowPtr)-1L,
- hasCloseBox,
- (long)this);
-
- // Special case with floating windows under system < 7.5
- if ((procID & 0xFFF0) == FW_kNonSystem75WindoidWDEF)
- {
- if (gMacFloatWindowProc == NULL)
- {
- gMacFloatWindowProc = ((WindowPeek)platformWindow)->windowDefProc;
- ::DetachResource(gMacFloatWindowProc);
- }
- else
- {
- Handle temp = ((WindowPeek)platformWindow)->windowDefProc;
- ((WindowPeek)platformWindow)->windowDefProc = gMacFloatWindowProc;
- ::ReleaseResource(temp);
- }
- }
-
- return platformWindow;
- }
- #endif
-
- //---------------------------------------------------------------------------------------
- // FW_CWindow::PrivCreateODWindow
- //---------------------------------------------------------------------------------------
-
- void FW_CWindow::PrivCreateODWindow(Environment* ev,
- ODPart* thePart,
- ODFrame* parentFrame,
- FW_Boolean persistent,
- ODTypeToken viewType,
- ODTypeToken presentation,
- const FW_CString& windowTitle,
- const FW_CPoint& interiorSize,
- const FW_CPoint& position,
- WindowStyle style)
- {
- FW_ASSERT(fWindowID == kODNULLID);
-
- ODWindowState* windowState = thePart->GetStorageUnit(ev)->GetSession(ev)->GetWindowState(ev);
-
- #ifdef FW_BUILD_MAC
- unsigned short procID = PrivMacStyleToProcId(ev, style);
-
- Str255 pascalTitle;
- windowTitle.ExportPascal(pascalTitle);
-
- FW_CPoint tempSize(FW_IntToFixed(100), FW_IntToFixed(100));
- FW_CPoint tempPos = tempSize;
- ODPlatformWindow platformWindow = PrivMacCreatePlatformWindow(ev,
- pascalTitle,
- tempSize,
- tempPos,
- procID,
- (FW_kHasCloseBox & style) != 0);
-
- // Set the right size
- ::SizeWindow(platformWindow, interiorSize.x.AsInt(), interiorSize.y.AsInt(), TRUE);
-
- // because MacCreatePlatformWindow is called with the inside position
- FW_CRect borderSize;
- FW_CWindow::PrivGetBorderSize(platformWindow, borderSize);
- ::MoveWindow(platformWindow,
- (position.x + borderSize.left).AsInt(),
- (position.y + borderSize.top).AsInt(),
- FALSE);
-
- #endif
-
- #ifdef FW_BUILD_WIN
- DWORD windowFlags = PrivWindStyleToWindowsFlags(style);
-
- ODPlatformWindow platformWindow = windowState->CreatePlatformWindow(ev, (style & FW_kFloatingWindow) != 0, windowFlags | WS_CLIPSIBLINGS);
-
- // Associate window pointer with the platform window
- if (platformWindow != NULL)
- {
- ::SetProp(platformWindow, "ODF:Window", (HANDLE) this);
- }
- #endif
-
- // ----- Create and return the wrapper window
- ODWindow* odWindow = windowState->RegisterWindow(ev,
- platformWindow,
- persistent ? kODFrameObject : kODNonPersistentFrameObject,
- (parentFrame == NULL) && ((FW_kFloatingWindow & style) == 0), // root window
- #ifdef FW_BUILD_MAC
- FALSE, // On the Mac we handle the resizing ourself
- #else
- (FW_kResizeable & style) != 0,
- #endif
- (FW_kFloatingWindow & style) != 0,
- persistent, // shouldSave (shouldSave and persistent should always have the same value)
- #ifdef FW_BUILD_MAC
- TRUE, // should dispose
- #endif
- thePart,
- viewType,
- presentation,
- parentFrame);
-
- fWindowID = odWindow->GetID(ev);
-
- FitToScreen(ev);
-
- odWindow->Open(ev);
-
- #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
- odWindow->Release(ev);
- #endif
-
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::GetGraphicDevice
- //----------------------------------------------------------------------------------------
-
- FW_CGraphicDevice* FW_CWindow::GetGraphicDevice(Environment* ev) const
- {
- FW_CWindow* self = (FW_CWindow *)this;
-
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
-
- ODFacet* rootFacet = aqODWindow->GetRootFacet(ev);
- FW_CGraphicDevice* device = FW_CFacetPartInfo::GetFacetGraphicDevice(ev, rootFacet);
-
- if (device == NULL)
- {
- if (fGraphicDevice == NULL) // We never asked for it
- {
- self->fGraphicDevice = new FW_CGraphicDevice(ev, rootFacet->GetCanvas(ev));
- }
- device = fGraphicDevice;
- }
-
- return device;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::SetWindowSize
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::SetWindowSize(Environment* ev, const FW_CPoint& interiorSize)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- ODPlatformWindow platformWindow = aqODWindow->GetPlatformWindow(ev);
-
- #ifdef FW_BUILD_MAC
- ::SizeWindow(platformWindow, interiorSize.x.AsInt(), interiorSize.y.AsInt(), TRUE);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_CRect borderSize;
- FW_CWindow::PrivGetBorderSize(platformWindow, borderSize);
-
- FW_SPlatformRect windowRect;
- ::GetWindowRect(platformWindow, &windowRect);
-
- int width = (interiorSize.x + borderSize.left + borderSize.right).AsInt();
- int height = (interiorSize.y + borderSize.top + borderSize.bottom).AsInt();
-
- ::MoveWindow(platformWindow, //::GetParent(platformWindow),
- windowRect.left, windowRect.top,
- width, height,
- TRUE);
- #endif
-
- // ----- Notify the ODWindow -----
- if (aqODWindow->GetRootFacet(ev) != NULL)
- aqODWindow->AdjustWindowShape(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::SetWindowPosition
- //----------------------------------------------------------------------------------------
- // newPosition is the position of the exterior top left corner of the window. This is
- // different from the Mac API where MoveWindow takes the inside top left corner
- // of the window. For once the Windows API makes more sense.
-
- void FW_CWindow::SetWindowPosition(Environment* ev, const FW_CPoint& newPosition)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- ODPlatformWindow platformWindow = aqODWindow->GetPlatformWindow(ev);
-
- #ifdef FW_BUILD_MAC
- FW_CRect borderSize;
- FW_CWindow::PrivGetBorderSize(platformWindow, borderSize);
-
- ::MoveWindow(platformWindow, (newPosition.x + borderSize.left).AsInt(), (newPosition.y + borderSize.top).AsInt(), FALSE);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_SPlatformRect windowRect;
- ::GetWindowRect(platformWindow, &windowRect);
-
- ::MoveWindow(platformWindow, //::GetParent(platformWindow),
- newPosition.x.AsInt(), newPosition.y.AsInt(),
- windowRect.right - windowRect.left,
- windowRect.bottom - windowRect.top,
- FALSE);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::WindowToScreen
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::WindowToScreen(Environment* ev,
- FW_CPoint* points,
- unsigned short nbPoint)
- {
- FW_ASSERT(nbPoint > 1);
-
- #ifdef FW_BUILD_MAC
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- GrafPtr curPort;
- ::GetPort(&curPort);
- ::SetPort(aqODWindow->GetPlatformWindow(ev));
-
- FW_SPlatformPoint plfmPoint;
- if (nbPoint == 1)
- {
- plfmPoint = *points;
- ::LocalToGlobal(&plfmPoint);
- *points = plfmPoint;
- }
- else
- {
- for (unsigned short i = 0; i<nbPoint; i++)
- {
- plfmPoint = points[i];
- ::LocalToGlobal(&plfmPoint);
- points[i] = plfmPoint;
- }
- }
-
- ::SetPort(curPort);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_DEBUG_MESSAGE("Not yet implemented");
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::ScreenToWindow
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::ScreenToWindow(Environment* ev,
- FW_CPoint* points,
- unsigned short nbPoint)
- {
- FW_ASSERT(nbPoint > 1);
-
- #ifdef FW_BUILD_MAC
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
-
- GrafPtr curPort;
- ::GetPort(&curPort);
- ::SetPort(aqODWindow->GetPlatformWindow(ev));
-
- FW_SPlatformPoint plfmPoint;
- if (nbPoint == 1)
- {
- plfmPoint = *points;
- ::GlobalToLocal(&plfmPoint);
- *points = plfmPoint;
- }
- else
- {
- for (unsigned short i = 0; i<nbPoint; i++)
- {
- plfmPoint = points[i];
- ::GlobalToLocal(&plfmPoint);
- points[i] = plfmPoint;
- }
- }
-
- ::SetPort(curPort);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_DEBUG_MESSAGE("Not yet implemented");
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::WindowToScreen
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::WindowToScreen(Environment* ev,
- FW_CRect& rect)
- {
- WindowToScreen(ev, (FW_CPoint*)&rect, 2);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::ScreenToWindow
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::ScreenToWindow(Environment* ev,
- FW_CRect& rect)
- {
- ScreenToWindow(ev, (FW_CPoint*)&rect, 2);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivFitRect
- //----------------------------------------------------------------------------------------
- // return:
- // 0: nothing changed
- // 1: position changed
- // 2: size changed
- // 3: position and size changed
-
- static short FW_PrivFitRect(const FW_CRect& containingRect, FW_CRect& rect)
- {
- short changed = 0;
-
- // ----- Be sure that it fits on the screen -----
- if (rect.left < containingRect.left)
- {
- changed |= 0x0001;
- rect.Offset(containingRect.left - rect.left, FW_kFixed0);
- }
-
- if (rect.top < containingRect.top)
- {
- changed |= 0x0001;
- rect.Offset(FW_kFixed0, containingRect.top - rect.top);
- }
-
- if (rect.right > containingRect.right)
- {
- changed |= 0x0001;
- rect.Offset(containingRect.right - rect.right, FW_kFixed0);
- if (rect.left < containingRect.left)
- {
- changed |= 0x0002;
- rect.left = containingRect.left;
- }
- }
-
- if (rect.bottom > containingRect.bottom)
- {
- changed |= 0x0001;
- rect.Offset(FW_kFixed0, containingRect.bottom - rect.bottom);
- if (rect.top < containingRect.top)
- {
- changed |= 0x0002;
- rect.top = containingRect.top;
- }
- }
-
- return changed;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::FitToScreen
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::FitToScreen(Environment* ev)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- ODPlatformWindow platformWindow = aqODWindow->GetPlatformWindow(ev);
-
- FW_CRect border;
- FW_CWindow::PrivGetBorderSize(platformWindow, border);
-
- #ifdef FW_BUILD_MAC
- FW_CRect screenRect;
- ::FW_MacGetMaxIntersectedDevice(platformWindow, screenRect);
- screenRect.Inset(FW_IntToFixed(3), FW_IntToFixed(3)); // leave space around window structure area
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_SPlatformRect plScreenRect;
- ::GetWindowRect(::GetDesktopWindow(), &plScreenRect);
- FW_CRect screenRect(plScreenRect);
- #endif
-
- #ifdef FW_BUILD_MAC
- FW_CPoint windowPos, windowSize;
-
- GetWindowPosition(ev, windowPos);
- GetWindowSize(ev, windowSize);
- FW_CRect windowRect(windowPos.x,
- windowPos.y,
- windowPos.x + windowSize.x + border.left + border.right,
- windowPos.y + windowSize.y + border.top + border.bottom);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_SPlatformRect plWindowRect;
- ::GetWindowRect(platformWindow, &plWindowRect);
- FW_CRect windowRect(plWindowRect);
- #endif
-
- short changed = FW_PrivFitRect(screenRect, windowRect);
-
- if ((changed & 0xFFFE) != 0)
- SetWindowPosition(ev, windowRect.TopLeft());
-
- if ((changed & 0xFFFD) != 0)
- {
- FW_CPoint windowSize(windowRect.Width() - border.left - border.right,
- windowRect.Height() - border.top - border.bottom);
- SetWindowSize(ev, windowSize);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::GetWindowSize
- //----------------------------------------------------------------------------------------
- // Returns the inside size of the window
-
- void FW_CWindow::GetWindowSize(Environment* ev, FW_CPoint& interiorSize) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- ODPlatformWindow platformWindow = aqODWindow->GetPlatformWindow(ev);
-
- #ifdef FW_BUILD_MAC
- interiorSize.x = FW_IntToFixed(platformWindow->portRect.right - platformWindow->portRect.left);
- interiorSize.y = FW_IntToFixed(platformWindow->portRect.bottom - platformWindow->portRect.top);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_SPlatformRect windowRect;
- ::GetWindowRect(platformWindow, &windowRect);
-
- FW_CRect borderSize;
- FW_CWindow::PrivGetBorderSize(platformWindow, borderSize);
-
- interiorSize.x = FW_IntToFixed(windowRect.right - windowRect.left) - borderSize.left - borderSize.right;
- interiorSize.y = FW_IntToFixed(windowRect.bottom - windowRect.top) - borderSize.top - borderSize.bottom;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::GetWindowPosition
- //----------------------------------------------------------------------------------------
- // Returns the outside position of the window
-
- void FW_CWindow::GetWindowPosition(Environment* ev, FW_CPoint& position) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- ODPlatformWindow platformWindow = aqODWindow->GetPlatformWindow(ev);
-
- #ifdef FW_BUILD_MAC
- GrafPtr curPort;
- ::GetPort(&curPort);
- ::SetPort(platformWindow);
- Point localToGlobal = {platformWindow->portRect.top, platformWindow->portRect.left};
- ::LocalToGlobal(&localToGlobal);
- ::SetPort(curPort);
-
- FW_CRect borderSize;
- FW_CWindow::PrivGetBorderSize(platformWindow, borderSize);
-
- position.x = FW_IntToFixed(localToGlobal.h) - borderSize.left;
- position.y = FW_IntToFixed(localToGlobal.v) - borderSize.top;
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_SPlatformRect windowRect;
- ::GetWindowRect(platformWindow, &windowRect);
-
- position.x = FW_IntToFixed(windowRect.left);
- position.y = FW_IntToFixed(windowRect.top);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::PrivGetBorderSize
- //----------------------------------------------------------------------------------------
- // Returns the size of the border in pixels
-
- void FW_CWindow::PrivGetBorderSize(ODPlatformWindow platformWindow, FW_CRect &borderSize)
- {
- FW_ASSERT(platformWindow != NULL);
-
- #ifdef FW_BUILD_MAC
- WindowRecord *windowRec = (WindowRecord*)platformWindow;
-
- FW_Boolean rgnsWereBuilt = FW_MacBuildWindowRegions(platformWindow, TRUE);
- FW_SPlatformRect outside = (*windowRec->strucRgn)->rgnBBox;
- FW_SPlatformRect inside = (*windowRec->contRgn)->rgnBBox;
- FW_MacBuildWindowRegions(platformWindow, rgnsWereBuilt);
- #endif
-
- #ifdef FW_BUILD_WIN
- DWORD dwStyle = (DWORD)::GetWindowLong(platformWindow, GWL_STYLE);
- DWORD dwExStyle = (dwStyle & DS_MODALFRAME) ? WS_EX_DLGMODALFRAME : 0L;
-
- FW_SPlatformRect inside;
- ::GetClientRect(platformWindow, &inside);
-
- FW_SPlatformRect outside(inside.left, inside.top, inside.right, inside.bottom);
-
- ::AdjustWindowRectEx(&outside, dwStyle ^ DS_MODALFRAME, FALSE, dwExStyle);
- #endif
-
- borderSize.left = FW_IntToFixed(inside.left - outside.left);
- borderSize.top = FW_IntToFixed(inside.top - outside.top);
- borderSize.right = FW_IntToFixed(outside.right - inside.right);
- borderSize.bottom = FW_IntToFixed(outside.bottom - inside.bottom);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::IsFloating
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CWindow::IsFloating(Environment* ev) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- return aqODWindow->IsFloating(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::IsActive
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CWindow::IsActive(Environment* ev) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- return aqODWindow->IsActive(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::GetPlatformWindow
- //----------------------------------------------------------------------------------------
-
- ODPlatformWindow FW_CWindow::GetPlatformWindow(Environment* ev) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- return aqODWindow->GetPlatformWindow(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::GetBorderSize
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::GetBorderSize(Environment* ev, FW_CRect &borderSize) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_CWindow::PrivGetBorderSize(aqODWindow->GetPlatformWindow(ev), borderSize);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::Close
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::Close(Environment* ev)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- aqODWindow->Close(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::Close
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::CloseAndRemove(Environment* ev)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- aqODWindow->CloseAndRemove(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::Select
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::Select(Environment* ev) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- aqODWindow->Select(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::IsShown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CWindow::IsShown(Environment* ev) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- return aqODWindow->IsShown(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::Hide
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::Hide(Environment* ev)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- aqODWindow->Hide(ev);
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CWindow::PrivMacTrackResizeWindow
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::PrivMacTrackResizeWindow(Environment* ev, const FW_CRect& growLimits, const FW_CMacWindowEvent& windowEvent)
- {
- ODEventData* eventData = ((FW_CMacWindowEvent&)windowEvent).GetPlatformEvent();
-
- FW_SPlatformRect plfmGrowLimits;
- growLimits.AsPlatformRect(plfmGrowLimits);
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- long newWindowSize = ::GrowWindow(aqODWindow->GetPlatformWindow(ev), eventData->where, &plfmGrowLimits);
-
- FW_CPoint interiorSize(FW_IntToFixed(LoWord(newWindowSize)), FW_IntToFixed(HiWord(newWindowSize)));
- this->SetWindowSize(ev, interiorSize);
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CWindow::PrivMacDoZoom
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::PrivMacDoZoom(Environment* ev,
- const FW_CPoint& zoomedSize,
- const FW_CRect& borderSize,
- const FW_CRect& screenRect,
- unsigned long message)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- ODPlatformWindow platformWindow = aqODWindow->GetPlatformWindow(ev);
-
- if (message == inZoomOut)
- {
- // ----- Calculate the outside bounds of the window -----
- FW_CPoint windowPos;
- GetWindowPosition(ev, windowPos);
-
- FW_CRect windowRect(windowPos.x,
- windowPos.y,
- windowPos.x + zoomedSize.x + borderSize.left + borderSize.right,
- windowPos.y + zoomedSize.y + borderSize.top + borderSize.bottom);
-
- // ----- Be sure that it fits on the screen -----
- FW_PrivFitRect(screenRect, windowRect);
-
- // ----- Calculate the inside -----
- windowRect.left += borderSize.left;
- windowRect.right -= borderSize.right;
- windowRect.top += borderSize.top;
- windowRect.bottom -= borderSize.bottom;
-
- // ----- and set the stdState -----
- windowRect.AsPlatformRect((*((WStateDataHandle)(((WindowPeek)platformWindow)->dataHandle)))->stdState);
- }
-
- ::FW_MacZoomWindow(platformWindow, message == inZoomIn);
-
- aqODWindow->AdjustWindowShape(ev);
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CWindow::PrivMacStyleToProcId
- //----------------------------------------------------------------------------------------
-
- unsigned short FW_CWindow::PrivMacStyleToProcId(Environment *ev, WindowStyle windowStyle)
- {
- unsigned short procId;
-
- if (windowStyle & FW_kStandardWindow)
- {
- if (windowStyle & FW_kResizeable)
- if (windowStyle & FW_kHasMaximizeBox)
- procId = zoomDocProc;
- else
- procId = documentProc;
- else if (windowStyle & FW_kHasMaximizeBox)
- procId = zoomNoGrow;
- else
- procId = noGrowDocProc;
- }
- else if (windowStyle & FW_kModelessDialog)
- {
- procId = documentProc;
- }
- else if (windowStyle & FW_kModalDialog)
- {
- if (windowStyle & FW_kHasCaption)
- procId = movableDBoxProc;
- else
- procId = dBoxProc;
-
- }
- else if (windowStyle & FW_kFloatingWindow)
- {
- // Check first if we have the system 7.5 resource
- Handle hld = ::GetResource('WDEF', 124);
- if (hld == NULL)
- procId = FW_kNonSystem75WindoidWDEF;
- else
- procId = FW_kSystem75WindoidWDEF;
-
- if (windowStyle & FW_kHasMaximizeBox)
- procId += FW_kSystem75HasZoom;
- if (windowStyle & FW_kResizeable)
- procId += FW_kSystem75HasGrow;
- }
- // else if (windowStyle & FW_kMacDesktopPane)
- // {
- // procId = plainDBox;
- // }
- else
- {
- FW_ASSERT(FALSE);
- procId = documentProc;
- }
-
- return procId;
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CWindow::PrivWindStyleToWindowsFlags
- //----------------------------------------------------------------------------------------
-
- DWORD FW_CWindow::PrivWindStyleToWindowsFlags(WindowStyle style)
- {
- DWORD dwStyle = 0;
-
- if (style & FW_kStandardWindow)
- dwStyle |= WS_CHILD;
- else if (style & FW_kOverlappedWindow)
- dwStyle |= WS_OVERLAPPED;
- else if (style & FW_kFloatingWindow)
- dwStyle |= /*WS_POPUP |*/ WS_CAPTION;
- else if (style & FW_kModelessDialog)
- dwStyle |= (WS_POPUP | DS_MODALFRAME);
- else if (style & FW_kModalDialog)
- dwStyle |= (WS_POPUP | DS_MODALFRAME);// DS_MODALFRAME will be transform into WS_EX_DLGMODALFRAME
- else
- FW_ASSERT(FALSE);
-
- if (style & FW_kResizeable)
- dwStyle |= WS_THICKFRAME;
-
- if (style & FW_kHasCaption)
- dwStyle |= WS_CAPTION;
-
- if (style & FW_kHasCloseBox)
- dwStyle |= WS_SYSMENU;
-
- if (style & FW_kHasMinimizeBox)
- dwStyle |= WS_MINIMIZEBOX;
-
- if (style & FW_kHasMaximizeBox)
- dwStyle |= WS_MAXIMIZEBOX;
-
- return dwStyle;
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CWindow::PrivWindFixSystemMenu
- //----------------------------------------------------------------------------------------
- // Makes system menu consistent with platform dialogs
-
- void FW_CWindow::PrivWindFixSystemMenu(WindowStyle windowStyle)
- {
- #if 0
- // Make system menu standard for windows dialogs
- HMENU fMenuHandle = ::GetSystemMenu(GetPlatformWindow(), FALSE);
-
- if (fMenuHandle != NULL)
- {
- BR_CBedrock* bedrock = BR_CBedrock::GetBedrock();
- BR_CCharString255 MenuText;
-
- // Delete all items
- while (::DeleteMenu(fMenuHandle, 0, MF_BYPOSITION))
- ;
-
- // Flags for ::AppendMenu()
- const WORD wfItemFlags = MF_BYCOMMAND | MF_ENABLED | MF_STRING;
-
- // Add in dialog menu
- if (windowStyle & (kHasMinimizeBox | FW_kHasMaximizeBox))
- {
- bedrock->LoadString(IDSL_SYSTEMMENU, IDS_RESTORE, MenuText);
- ::AppendMenu(fMenuHandle, wfItemFlags, SC_RESTORE, MenuText);
- }
-
-
- {
- bedrock->LoadString(IDSL_SYSTEMMENU, IDS_MOVE, MenuText);
- ::AppendMenu(fMenuHandle, wfItemFlags, SC_MOVE, MenuText);
- }
-
- if (windowStyle & FW_kResizeable)
- {
- bedrock->LoadString(IDSL_SYSTEMMENU, IDS_SIZE, MenuText);
- ::AppendMenu(fMenuHandle, wfItemFlags, SC_SIZE, MenuText);
- }
-
- if (windowStyle & FW_kHasMinimizeBox)
- {
- bedrock->LoadString(IDSL_SYSTEMMENU, IDS_MINIMIZE, MenuText);
- ::AppendMenu(fMenuHandle, wfItemFlags, SC_MINIMIZE, MenuText);
- }
-
- if (windowStyle & FW_kHasMaximizeBox)
- {
- bedrock->LoadString(IDSL_SYSTEMMENU, IDS_MAXIMIZE, MenuText);
- ::AppendMenu(fMenuHandle, wfItemFlags, SC_MAXIMIZE, MenuText);
- }
-
- ::AppendMenu(fMenuHandle, MF_SEPARATOR, 0, NULL);
-
- {
- bedrock->LoadString(IDSL_SYSTEMMENU, IDS_CLOSE, MenuText);
- ::AppendMenu(fMenuHandle, wfItemFlags, SC_CLOSE, MenuText);
- }
- }
- #endif
- }
- #endif
-